package chamster;

import java.util.HashMap;

import chamster.actions.ForewardAction;
import chamster.actions.HamsterAction;
import chamster.actions.TurnLeftAction;
import chamster.actions.TurnRightAction;
import chamster.random.RandomStatelessActionMachine;
import chamster.random.TurnWithChanceRandomMachine;

public class TurnWithChanceHamster extends BaseHamster {
 
	private final RandomStatelessActionMachine<TurnWithChanceHamster> decisionMaker;
	
	public TurnWithChanceHamster(int leftChance, int rightChance,
			int forewardChance, double multiplier) {
		super();
		HashMap<HamsterAction<TurnWithChanceHamster>, Integer> actions = 
				new HashMap<HamsterAction<TurnWithChanceHamster>, Integer>();
		actions.put(new TurnLeftAction<TurnWithChanceHamster>(), leftChance);
		actions.put(new TurnRightAction<TurnWithChanceHamster>(), rightChance);
		actions.put(new ForewardAction<TurnWithChanceHamster>(), forewardChance);
		this.decisionMaker = new TurnWithChanceRandomMachine(actions, multiplier);
	}
	
	@Override
	public void life() throws Exception {
		while(super.chargeLeft(1)) {
			this.decisionMaker.decideAndExecute(this);
			if(super.canPickup()) {
				super.pickup();
			}
		}
	}
}
